<?php

class blockbgzopim extends Module {
	
	public function __construct() {
		$this->name = 'blockbgzopim';
		$this->tab = version_compare(_PS_VERSION_, '1.4.0.0', '>=')?'advertising_marketing':'gsvision';
		$this->version = '1.0';
		$this->author = 'GS VISION Studio';
		parent::__construct();
		$this->displayName = $this->l('Block BG Zopim');
		$this->description = $this->l('Внедрява услугите на Zopim.com за чат на живо с вашите клиенти.');
	}
	
	function install()
	{
		if (!parent::install() 
			OR !$this->registerHook('footer')
			OR Configuration::updateValue('ZOPIM', '') == false)
			return false;
		return true;
	}
	
	function uninstall()
	{
		if (!Configuration::deleteByName('ZOPIM') OR !parent::uninstall())
			return false;
		return true;
	}

	public function getContent()
	{
		$output = '<h2><a href="http://www.presta.bg"><img src="'.$this->_path.'logo.gif" alt="" /></a>'.$this->displayName.'</h2>';
		if (Tools::isSubmit('submitblockzopim'))
		{
			$zopimscript = Tools::getValue('zopimscript');
			
			Configuration::updateValue('ZOPIM', $zopimscript);
			$output .= '<div class="conf confirm"><img src="../img/admin/ok.gif" alt="'.$this->l('Confirmation').'" />'.$this->l('Settings updated').'</div>';
		}
		return $output.$this->displayForm();
	}

	public function displayForm()
	{
		return '
		<form action="'.$_SERVER['REQUEST_URI'].'" method="post">
			<p>'.$this->l('Above all things, subscribe to').' <a href="https://www.zopim.com/affiliates/landing/gsvision" title="'.$this->l('Above all things, subscribe to').' ZOPIM" target="_blank" style="color:orange"><b>ZOPIM</b></a></p>
			<fieldset>
				<legend><a href="http://www.presta.bg"><img src="'.$this->_path.'logo.gif" alt="" /></a>'.$this->l('Settings').'</legend>
				
				<label><a href="https://www.zopim.com/affiliates/landing/gsvision" target="_blank" title="'.$this->l('Zopim live chat solutions Create your account').'"><img src="'.$this->_path.'zopimlogo.gif" alt="'.$this->l('Zopim live chat solutions').'" /></a></label>
				<div class="margin-form"><input type="text" name="zopimscript" value="'.Configuration::get('ZOPIM').'" />
					<p>'.$this->l('To configure this module, after registering on').' <a href="https://www.zopim.com/affiliates/landing/gsvision" title="'.$this->l('Above all things, subscribe to').' ZOPIM" target="_blank" style="color:orange"><b>ZOPIM</b></a>, '.$this->l('get code to insert the script and find the ID of your site in bold red represent the example below. Enter the ID above.').'</p>
					<p class="clear">&lt;!-- Start of Zopim Live Chat Script --&gt;<br />
					&lt;script type=&quot;text/javascript&quot;&gt;<br />
					document.write(unescape(&quot;%3Cscript src=\'&quot; + document.location.protocol + &quot;//zopim.com/?<b><span style="color:#900" title="'.$this->l('Copy your site ID represented like this one').'">Ls3s2zqg6mTq4laFyAfVeLkTVnK5YPHn</span></b>\' charset=\'utf-8\' type=\'text/javascript\'%3E%3C/script%3E&quot;));<br />
					&lt;/script&gt;<br />
					&lt;!-- End of Zopim Live Chat Script --&gt;</p>
				</div>
				
				<center><input type="submit" name="submitblockzopim" value="'.$this->l('Save').'" class="button" /></center>
			</fieldset>
		</form>
		';
	}

	function hookFooter($params)
	{
		global $smarty;
		if (Configuration::get('ZOPIM') != "") {
			$zopim = Configuration::get('ZOPIM');
			$smarty->assign(array('zopim' => $zopim));
			return $this->display(__FILE__, 'blockbgzopim.tpl');
		}
		return $output;
	}
}

?>
